package com.atguigu.springboot.comtroller;

import com.atguigu.springboot.entity.Department;
import com.atguigu.springboot.service.IDepartmentService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author : wenchao.long
 * @date : Created in 2020/11/26 10:22 周四
 * @description :
 */
@RestController()
@RequestMapping("/department")
@AllArgsConstructor
public class DepartmentController {

    private final IDepartmentService departmentService;

    @GetMapping
    public Department getDepartment(@RequestParam("id") Integer id) {
        return departmentService.getById(id);
    }

    @PutMapping
    public Department insert(@RequestBody Department department) {
        departmentService.insert(department);
        return department;
    }

    @PostMapping
    public Department update(@RequestBody Department department) {
        return departmentService.update(department);
    }

    @DeleteMapping
    public void delete(@RequestParam("id") Integer id) {
        departmentService.deleteById(id);
    }
}
